package com.free.fs.controller;

import com.free.fs.common.domain.Result;
import com.free.fs.core.domain.dto.UpdatePasswordDTO;
import com.free.fs.core.service.UserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import com.free.fs.core.domain.User;
import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission;
/**
 * 用户控制器
 *

 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    /**
     * 修改密码
     *
     * @param dto
     * @return
     */
    @PutMapping("/password")
    @ResponseBody
    public Result<?> updatePassword(@Valid @RequestBody UpdatePasswordDTO dto) {
        if (userService.updatePassword(dto)) {
            return Result.ok("修改成功");
        }
        return Result.error("修改失败");
    }
    /**
     * 管理员获取所有用户信息
     * @return 用户列表
     */
    @GetMapping("/all")

    @SaCheckPermission("admin:user:view")
    public Result<?> getAllUsers() {
        List<User> users = userService.getAllUsers();
        return Result.ok(users, "查询成功");
    }
}
